const rewriteList = [
  {path:'login',to:'login'},
  {path:'address',to:'main'},
  {path:'brand',to:'main'},
  {path:'order',to:'main'},
  {path:'product',to:'main'},
  {path:'refund',to:'main'},
  {path:'statistics',to:'main'},
  {path:'system',to:'main'},
  {path:'wxcategory',to:'main'},
  {path:'classify',to:'main'},
  {path:'banner',to:'main'},
  {path:'market',to:'main'},
  {path:'integralSetting',to:'main'},
  {path:'user',to:'main'},
  {path:'wxacc',to:'main'},
  
]

const serverProxy = [
  {
    api:'/api',
    // target:'https://yql-admin-dev.77s.vip',
    target:'http://localhost:8080',
    // target:'https://fans-admin.sibumbg.com',
    pathRewrite:{
      '^/api':'/'
    }
  }
]
exports.serverProxy=serverProxy
exports.rewriteList=rewriteList
module.exports.getDevServer = (isEnvProduction,port)=>{
  if(isEnvProduction) return {}
  return {
    port: port,
    open: true,
    proxy:serverProxy.reduce((proxy,it)=>{
      proxy[it.api]={
        target:it.target,
        changeOrigin: true,
        secure:false,
        pathRewrite:it.pathRewrite
      }
      return proxy
    },{}),
    // proxy: {
    //   '/api': {
    //     target: 'http://higo-2b-api.meibugou.cn',
    //     changeOrigin: true,
    //     secure:false, // true/false, if you want to verify the SSL Certs
    //     pathRewrite:{
    //       '^/api':'/'
    //     }
    //   }
    // },
    historyApiFallback: {
      rewrites:rewriteList.map(it=>{
        return {
          // from:new RegExp(`^/${it.path}/`),to:`/${it.to}/index.html`
          from:new RegExp(`^/${it.path}/`),to:`/${it.to}.html`
        }
      })
      // rewrites: [
      //   {from:new RegExp(`^/login/`),to:`/login/index.html`},
      //   {from:new RegExp(`^/workspace/`),to:`/workspace/index.html`},
      // ],
    },
    hot:true,
    client: {
      //警告弹出
      overlay: {
        errors: true,
        warnings: true,
        runtimeErrors: false,
      },
    }
  }
}